<?php
/**
 * 异步通知
 */
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use pay\Config;

$db     = new Datebase();

$param = $db->param();
file_put_contents('data.txt', json_encode($param)."\r\n",FILE_APPEND);

$sign = $param['sign'];
unset($param['sign']);
if (isset($param['attach'])) unset($param['attach']);
if (isset($param['message'])) unset($param['message']);

$sign1           = Config::getSign($dataArray, Config::$key);
$merchantTradeNo = $param['order_id'];
$position        = strrpos($merchantTradeNo, 'U');
$orderNumber     = substr($merchantTradeNo, 0, $position);
$uid             = substr($merchantTradeNo, $position+1);

//验签
if($sign === $sign1 && $param['code'] == '00') {
    $res = $Db->runUpdate([
        'money'         =>  $param['price'] / 100,
        'order_number'  =>  $merchantTradeNo,
        'uid'           =>  $uid,
    ]);
    if ($res) {
        echo 'OK';
    } else {
        file_put_contents('data.txt', '上分失败'.$sign1."\r\n",FILE_APPEND);
        echo '上分失败';
    }
}else {
    file_put_contents('data.txt', '验签失败'.$sign1."\r\n",FILE_APPEND);
	echo '验签失败';
}